import { request } from './api-service';

const LIMIT_OF_CARS = 7;

export function getCars(page?: number, limit = LIMIT_OF_CARS) {
  if (page && limit) {
    return request(`garage?_page=${page}&_limit=${limit}`);
  }
  return request(`garage`);
}

export function getCar(id: number) {
  return request(`garage/${id}`);
}

export function createCar(name: string, color: string) {
  return request(`garage`, {
    body: { name, color },
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
  });
}

export function deleteCar(id: number) {
  return request(`garage/${id}`, { method: 'DELETE' });
}

export function updateCar(id: number, name: string, color: string) {
  return request(`garage/${id}`, {
    body: { name, color },
    method: 'PUT',
    headers: { 'Content-Type': 'application/json' },
  });
}
